<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="课表详情ID" prop="scheduleInfoId">
        <el-input
          v-model="queryParams.scheduleInfoId"
          placeholder="请输入课表详情ID"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原上课日期" prop="oldScheduleDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.oldScheduleDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择原上课日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="原星期几" prop="oldWeekDay">
        <el-input
          v-model="queryParams.oldWeekDay"
          placeholder="请输入原星期几"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原上课时段" prop="oldScheduleSegment">
        <el-input
          v-model="queryParams.oldScheduleSegment"
          placeholder="请输入原上课时段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="原课次" prop="oldCourseTimes">
        <el-input
          v-model="queryParams.oldCourseTimes"
          placeholder="请输入原课次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新上课日期" prop="newScheduleDate">
        <el-date-picker clearable size="small" style="width: 200px"
          v-model="queryParams.newScheduleDate"
          type="date"
          value-format="yyyy-MM-dd"
          placeholder="选择新上课日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="新星期几" prop="newWeekDay">
        <el-input
          v-model="queryParams.newWeekDay"
          placeholder="请输入新星期几"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新上课时段" prop="newScheduleSegment">
        <el-input
          v-model="queryParams.newScheduleSegment"
          placeholder="请输入新上课时段"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="新课次" prop="newCourseTimes">
        <el-input
          v-model="queryParams.newCourseTimes"
          placeholder="请输入新课次"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="状态" prop="status">
        <el-select v-model="queryParams.status" placeholder="请选择状态" clearable size="small">
          <el-option label="请选择字典生成" value="" />
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button type="cyan" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['edu:transfer:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['edu:transfer:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['edu:transfer:remove']"
        >删除</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['edu:transfer:export']"
        >导出</el-button>
      </el-col>
	  <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table v-loading="loading" :data="transferList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="调课ID" align="center" prop="transferId" />
      <el-table-column label="课表详情ID" align="center" prop="scheduleInfoId" />
      <el-table-column label="原上课日期" align="center" prop="oldScheduleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.oldScheduleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="原星期几" align="center" prop="oldWeekDay" />
      <el-table-column label="原上课时段" align="center" prop="oldScheduleSegment" />
      <el-table-column label="原课次" align="center" prop="oldCourseTimes" />
      <el-table-column label="新上课日期" align="center" prop="newScheduleDate" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.newScheduleDate, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="新星期几" align="center" prop="newWeekDay" />
      <el-table-column label="新上课时段" align="center" prop="newScheduleSegment" />
      <el-table-column label="新课次" align="center" prop="newCourseTimes" />
      <el-table-column label="状态" align="center" prop="status" />
      <el-table-column label="备注" align="center" prop="remark" />
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            v-hasPermi="['edu:transfer:edit']"
          >修改</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="handleDelete(scope.row)"
            v-hasPermi="['edu:transfer:remove']"
          >删除</el-button>
        </template>
      </el-table-column>
    </el-table>
    
    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改调课信息对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="800px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-form-item label="课表详情ID" prop="scheduleInfoId">
          <el-input v-model="form.scheduleInfoId" placeholder="请输入课表详情ID" />
        </el-form-item>
        <el-form-item label="原上课日期" prop="oldScheduleDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.oldScheduleDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择原上课日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="原星期几" prop="oldWeekDay">
          <el-input v-model="form.oldWeekDay" placeholder="请输入原星期几" />
        </el-form-item>
        <el-form-item label="原上课时段" prop="oldScheduleSegment">
          <el-input v-model="form.oldScheduleSegment" placeholder="请输入原上课时段" />
        </el-form-item>
        <el-form-item label="原课次" prop="oldCourseTimes">
          <el-input v-model="form.oldCourseTimes" placeholder="请输入原课次" />
        </el-form-item>
        <el-form-item label="新上课日期" prop="newScheduleDate">
          <el-date-picker clearable size="small" style="width: 200px"
            v-model="form.newScheduleDate"
            type="date"
            value-format="yyyy-MM-dd"
            placeholder="选择新上课日期">
          </el-date-picker>
        </el-form-item>
        <el-form-item label="新星期几" prop="newWeekDay">
          <el-input v-model="form.newWeekDay" placeholder="请输入新星期几" />
        </el-form-item>
        <el-form-item label="新上课时段" prop="newScheduleSegment">
          <el-input v-model="form.newScheduleSegment" placeholder="请输入新上课时段" />
        </el-form-item>
        <el-form-item label="新课次" prop="newCourseTimes">
          <el-input v-model="form.newCourseTimes" placeholder="请输入新课次" />
        </el-form-item>
        <el-form-item label="状态">
          <el-radio-group v-model="form.status">
            <el-radio label="1">请选择字典生成</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="删除标志" prop="delFlag">
          <el-input v-model="form.delFlag" placeholder="请输入删除标志" />
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button size="mini" type="primary" @click="submitForm">确 定</el-button>
        <el-button size="mini" @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listTransfer, getTransfer, delTransfer, addTransfer, updateTransfer, exportTransfer } from "@/api/edu/transfer";

export default {
  name: "Transfer",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 调课信息表格数据
      transferList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        scheduleInfoId: null,
        oldScheduleDate: null,
        oldWeekDay: null,
        oldScheduleSegment: null,
        oldCourseTimes: null,
        newScheduleDate: null,
        newWeekDay: null,
        newScheduleSegment: null,
        newCourseTimes: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        scheduleInfoId: [
          { required: true, message: "课表详情ID不能为空", trigger: "blur" }
        ],
        oldCourseTimes: [
          { required: true, message: "原课次不能为空", trigger: "blur" }
        ],
        newCourseTimes: [
          { required: true, message: "新课次不能为空", trigger: "blur" }
        ],
      }
    };
  },
  created() {
    this.getList();
  },
  methods: {
    /** 查询调课信息列表 */
    getList() {
      this.loading = true;
      listTransfer(this.queryParams).then(response => {
        this.transferList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        transferId: null,
        scheduleInfoId: null,
        oldScheduleDate: null,
        oldWeekDay: null,
        oldScheduleSegment: null,
        oldCourseTimes: null,
        newScheduleDate: null,
        newWeekDay: null,
        newScheduleSegment: null,
        newCourseTimes: null,
        status: "0",
        delFlag: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.transferId)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加调课信息";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const transferId = row.transferId || this.ids
      getTransfer(transferId).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改调课信息";
      });
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.transferId != null) {
            updateTransfer(this.form).then(response => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addTransfer(this.form).then(response => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const transferIds = row.transferId || this.ids;
      this.$confirm('是否确认删除调课信息编号为"' + transferIds + '"的数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return delTransfer(transferIds);
        }).then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm('是否确认导出所有调课信息数据项?', "警告", {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }).then(function() {
          return exportTransfer(queryParams);
        }).then(response => {
          this.download(response.msg);
        })
    }
  }
};
</script>
